/*
 * User: rant
 * Date: 14/01/2007
 *
 *
 */
package laMalinche.rete.nodes;

import laMalinche.rete.rule.Condition;

import java.util.*;

/**
 this condition is used as a triger to update group of production rules
 updating it will update the whole group.
 */
public class TrigerConditionNode<T extends Condition> extends BasicConditionNode<T> implements Condition {
	private final List<AfterTrigerListener> afterTrigerListeners = new ArrayList();

	public void addAfterTrigerListener(AfterTrigerListener afterTrigerListener) {
		if (!afterTrigerListeners.contains(afterTrigerListener)) {
			afterTrigerListeners.add(afterTrigerListener);
		}
	}

	public List<AfterTrigerListener> getAfterTrigerListeners() {
		return afterTrigerListeners;
	}

	public void removeAfterTrigerListener(AfterTrigerListener afterTrigerListener) {
		afterTrigerListeners.remove(afterTrigerListener);
	}

	protected void adviseAfterTrigerListeners() {
		final List<AfterTrigerListener> afterTrigerListeners = getAfterTrigerListeners();
		for (AfterTrigerListener listener : afterTrigerListeners) {
			listener.wasTrigered(this);
		}
	}

	public TrigerConditionNode() {
		setConditionMet(Boolean.FALSE);
	}

	public void update() {
		setConditionMet(Boolean.TRUE);
		setConditionMet(Boolean.FALSE);
		adviseAfterTrigerListeners();
	}

	public void initialize() {
	}

	@Override
	public void detach() {
	}

	@Override
	protected void informChangeRelevancy(final boolean relevant) {
//		update();
	}

	public boolean isDisjunction() {
		return false;
	}

	public boolean isComplied() {
		return false;
	}
}